
package com.feib.stms.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.feib.stms.security.web.authentication.logout.ForceLogoutJob;
import com.feib.stms.service.ScheduleService;
import com.feib.stms.util.SpringContextUtil;

/**
 * @title (#)ScheduleServiceImpl.java<br>
 * @description <br>
 * @author Karl Chen<br>
 * @version 1.0.0 2012/06/19
 * @2012/06/19 create by Karl Chen<br>
 */
@Service("scheduleService")
public class ScheduleServiceImpl extends BaseServiceImpl implements ScheduleService {

	private static final long serialVersionUID = -2866556868637427803L;

	/* (non-Javadoc)
     * @see com.feib.stms.service.ScheduleService#doForceLogout()
     */
    @Scheduled(fixedDelay=180000) // 3 分鐘起來一次
    public void doForceLogout() {
        Date start = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        try {
            ForceLogoutJob.logger.info("強迫登出開始 -" + dateFormat.format(start));
            ForceLogoutJob forceLogoutJob = (ForceLogoutJob)SpringContextUtil.getBean("forceLogoutJob");
            forceLogoutJob.execute(null);
        }
        catch (Exception e) {
            ForceLogoutJob.logger.error("強迫登除排程執行失敗", e);
        }
        finally{
            Date end = new Date();
            ForceLogoutJob.logger.info("強迫登出結束 -" + dateFormat.format(end));
            ForceLogoutJob.logger.info("共費時  - " + ((end.getTime() - start.getTime()) / 1000) + " 秒 ");
        }
    }

}
